{include file="public/meta" /}
<title>数据库管理</title>
</head>
<body>
<!--_header 作为公共模版分离出去-->
{include file="public/header" /}
<!--/_header 作为公共模版分离出去-->
<!--_menu 作为公共模版分离出去-->
{include file="public/leftmenu" /}
<!--/_menu 作为公共模版分离出去-->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> <a href="{:url('Index/index')}">首页</a> <span class="c-gray en">&gt;</span> 数据库管理 <span class="c-gray en">&gt;</span> 数据库还原<a id="btn-refresh" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="mt-20">
                <table class="table table-border table-bordered table-hover table-bg table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="40">备份名称</th>
                        <th width="60">卷数</th>
                        <th width="100">压缩</th>
                        <th width="100">数据大小</th>
                        <th width="100">备份时间</th>
                        <th width="60">状态</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                    {volist name="list" id="val"}
                    <tbody>
                    <tr class="text-c">
                        <td>{$val['time']}</td>
                        <td>{$val['part']}</td>
                        <td>{$val['compress']}</td>
                        <td>{$val['size']}</td>
                        <td>{$val['time']|date='Y-m-d H:i:s',###}</td>
                        <td>{$val['time']}</td>
                        <td class="td-manage">
                            <a title="还原" href="javascript:;" onclick="data_revert('{$val.time}','','')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe642;</i></a>
                            <a title="删除" href="javascript:;" onclick="data_del(this,'{$val.time}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                    </tbody>
                    {/volist}
                </table>
            </div>
        </article>
    </div>
</section>
<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /}
<!--/_footer /作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__LIB__/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    $(function(){
        $('.table-sort').dataTable({
            "aaSorting": [[ 1, "desc" ]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,6]}// 制定列不参与排序
            ]
        });
        $('.table-sort tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            else {
                $('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        });
    });
    /*还原*/
    function data_revert(time, part, start){
        layer.confirm('确认要恢复吗？',function(index) {
            importData(time, part, start);
        })
    }
    function importData(time, part, start){
        $.ajax({
            url: "{:url('Data/revert')}",
            type: 'post',
            data: {"time":time,"part":part,"start":start},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.code == 2) {
                    layer.msg(data.msg, {icon: 6});
                } else if (data.code == 0) {
                    importData(time,data.data.part,data.data.start);
                    layer.msg("正在还原...");
                } else {
                    layer.msg(data.msg, {icon: 5});
                }
            },
            error: function (data) {
                layer.msg(data.msg, {icon: 5, time: 1000});
            }
        });
    }
    /*删除*/
    function data_del(obj,time){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                url:"{:url('Data/del')}",
                type:'post',
                data:{'time':time},
                dataType:'json',
                success:function(data){
                    if(data.code==0)
                    {
                        $(obj).parents("tr").remove();
                        layer.msg(data.msg,{icon:6,time:1000});
                    }
                    else{
                        layer.msg(data.msg,{icon:5,time:1000});
                    }
                },
                error:function(data){
                    layer.msg(data.msg,{icon:5,time:1000});
                }
            });
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>